'''
Created on Sep 23, 2011

@author: root
'''
import wx
import main.SpiInstance as SpiInstance

class LoginDlg(wx.Dialog):
    def __init__(self, parent, id= -1 , title='Login'):
        wx.Dialog.__init__(self, parent, id , title, size=(250, 210))
        
        self.parent = parent
        
        vbox = wx.BoxSizer(wx.VERTICAL)

        hbox_broker_id = wx.BoxSizer(wx.HORIZONTAL)
        broker_id = wx.StaticText(self, -1, 'broker_id', size=(70, 30))
        self.broker_id_txt = wx.TextCtrl(self, -1, '2030', (95, 105))
        hbox_broker_id.Add(broker_id, 1)
        hbox_broker_id.Add(self.broker_id_txt, 1, wx.LEFT, 5)
        
        hbox_investor_id = wx.BoxSizer(wx.HORIZONTAL)
        investor_id = wx.StaticText(self, -1, 'investor_id', size=(70, 30))
        self.investor_id_txt = wx.TextCtrl(self, -1, '00092', (95, 105))
        hbox_investor_id.Add(investor_id, 1)
        hbox_investor_id.Add(self.investor_id_txt, 1, wx.LEFT, 5)
        
        hbox_passwd = wx.BoxSizer(wx.HORIZONTAL)
        passwd = wx.StaticText(self, -1, 'passwd', size=(70, 30))
        self.passwd_txt = wx.TextCtrl(self, -1, '888888', (95, 105))
        hbox_passwd.Add(passwd, 1)
        hbox_passwd.Add(self.passwd_txt, 1, wx.LEFT, 5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        okButton = wx.Button(self, -1, 'Ok', size=(70, 30))
        closeButton = wx.Button(self, -1, 'Close', size=(70, 30))
        hbox.Add(okButton, 1)
        hbox.Add(closeButton, 1, wx.LEFT, 5)
        
        self.Bind(wx.EVT_BUTTON, self.onOk, okButton)
        self.Bind(wx.EVT_BUTTON, self.onClose, closeButton)

        vbox.Add(hbox_broker_id)
        vbox.Add(hbox_investor_id)
        vbox.Add(hbox_passwd)
        vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)

        self.SetSizer(vbox)
        
    def onOk(self, e):
        SpiInstance.SpiInstance.initUser(self.parent, self.broker_id_txt.GetValue(),
                                     self.investor_id_txt.GetValue(),
                                     self.passwd_txt.GetValue())
        self.Close()
        pass
    
    def onClose(self, e):
        self.Close()
